home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5239 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.8 KB

  1. Path: newsfeed.internetmci.com!xmission!news
  2. From: tknarr@xmission.com  ( Todd Knarr )
  3. Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
  4. Subject: Re: Undefined behavior? on type conversion, was: Re: Hungarian notation
  5. Date: 3 Feb 1996 05:28:26 GMT
  6. Organization: Chaos Central
  7. Message-ID: <4eurpq$b75@news.xmission.com>
  8. References: <30C40F77.53B5@swsbbs.com> <4d2ok0$69s@beach.and.nl> <4er2qo$h2s@galaxy.ucr.edu> <31118641.6802368@nntp.ix.netcom.com>
  9. Reply-To: tknarr@xmission.com ( Todd Knarr )
  10. NNTP-Posting-Host: slc113.xmission.com
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <31118641.6802368@nntp.ix.netcom.com>, miker3@ix.netcom.com (Mike Rubenstein) writes:
  14. >> : |> Repeating the quote from ISO 6.2.1.2
  15. >> : 
  16. >> : |>     When a value with integral type is demoted to a signed integer
  17. >> : |>     with smaller size or an unsigned integer is converted to its 
  18. >> : |>     corresponding signed integer, if the value cannot be 
  19. >> : |>     represented the result is implementation defined.
  20.  
  21. >Consider a machine with 8 bit char and the expression
  22. >
  23. >    (char) 256
  24. >
  25. >Here we have correct syntax and correct data.  The standard says that
  26. >this converts the number 256 to a char.  I believe I have a right to
  27. >assume that this will be done.
  28.  
  29. Except that 6.2.1.2 says you can't assume that. Your particular
  30. implementation may let you assume that, but the standard doesn't
  31. require it to. On machines with the capability of extracting the
  32. low-order bits the reasonable thing to do would be to fill in the
  33. char with the low-order byte ( 0 in your example ), but the
  34. standard doesn't say the machine has to have that capability, or
  35. that the implementation has to excercise it, or that the implementation
  36. has to be reasonable. As I asked before, do you think that, on a
  37. machine where the natural hardware response to your example would be
  38. a machine check and system halt, the committee intended to require
  39. that the compiler insert a range check before every such conversion?
  40.  
  41. As for "result" vs. "behavior", while I don't have the standard in
  42. front of me I believe that in the case of the ++ and -- operators the
  43. side-effect increment and decrement is also referred to as a result.
  44. If that is so, then their use of "result" doesn't rule out side-effects
  45. in the conversion, which can be anything since the implementation gets
  46. to define them.
  47.  
  48. Can you tell I tend to read the standard conservatively? I've been
  49. burned once too often by assuming things that weren't explicitly
  50. spelled out.
  51.  
  52. --
  53. Todd Knarr : tknarr@xmission.com      |  finger for PGP public key
  54.                                       |  Member, USENET Cabal
  55.  
  56. Seriously, I don't want to die just yet.  I don't care how
  57. good-looking they are, I! don't! want! to! die!"
  58.                                         -- Megazone ( UF1 )
  59.  
  60.